﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 学生选课及成绩查询管理系统
{
    public partial class updateClassInfo : Form
    {
        public updateClassInfo()
        {
            InitializeComponent();
        }

        private void btn_sub_Click(object sender, EventArgs e)
        {
            string classno = txt_classno.Text;
            string classname = txt_classname.Text;
            if (string.IsNullOrEmpty(classno) || string.IsNullOrEmpty(classname))
            {
                MessageBox.Show("信息输入不完整");
                return;
            }
            string sql = "update dbo.class set classname=@classname where classno=@classno";
            SqlParameter[] arraysql = { new SqlParameter("@classname", classname), new SqlParameter("@classno", classno)};
            int res = DBAccess.GetState(sql, arraysql);
            if (res != 0)
            {
                MessageBox.Show("修改该班级信息成功");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void txt_classname_Click(object sender, EventArgs e)
        {
            string classno = txt_classno.Text;
            string sql = "select count(*) from dbo.class where classno=@classno";
            SqlParameter[] arraysql = { new SqlParameter("@classno", classno) };
            object o = DBAccess.GetOne(sql, arraysql);
            if ((int)o == 1)
            {
                txt_tishi.Text = "✓";
                txt_tishi.ForeColor = Color.Green;
            }
            else
            {
                MessageBox.Show("请输入正确的班级号号");
                txt_classno.Focus();
                return;
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
